package com.isunland.managesystem.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.ProductLedgerOriginal;
import java.util.List;

/**
 * Created by lenovo on 2016/4/21.
 */
public class ChooseProductListAdapter
    extends ArrayAdapter<ProductLedgerOriginal.ProductLedgerContent> {
  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2015-12-17 17:36:31 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final LinearLayout rootView;
    public final TextView tvProductName;
    public final TextView tvProductNum;
    public final TextView tvProductType;
    public final TextView tvMunit;
    public final CheckBox cbProduct;

    private ViewHolder(LinearLayout rootView, TextView tvProductName, TextView tvProductNum,
        TextView tvProductType, TextView tvMunit, CheckBox cbProduct) {
      this.rootView = rootView;
      this.tvProductName = tvProductName;
      this.tvProductNum = tvProductNum;
      this.tvProductType = tvProductType;
      this.tvMunit = tvMunit;
      this.cbProduct = cbProduct;
    }

    public static ViewHolder create(LinearLayout rootView) {
      TextView tvProductName = (TextView) rootView.findViewById(R.id.tv_product_name);
      TextView tvProductNum = (TextView) rootView.findViewById(R.id.tv_product_num);
      TextView tvProductType = (TextView) rootView.findViewById(R.id.tv_product_type);
      TextView tvMunit = (TextView) rootView.findViewById(R.id.tv_munit);
      CheckBox cbProduct = (CheckBox) rootView.findViewById(R.id.cb_product);
      return new ViewHolder(rootView, tvProductName, tvProductNum, tvProductType, tvMunit,
          cbProduct);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_product_list, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    ProductLedgerOriginal.ProductLedgerContent item = getItem(position);

    vh.tvProductName.setText(item.getProductName());//产品名称
    vh.tvProductNum.setText(item.getMtype());//产品型号
    vh.tvProductType.setText(item.getMaterialKindCom());//产品类别
    vh.tvMunit.setText(item.getMunit());//标准单位
    vh.cbProduct.setVisibility(View.GONE);

    return vh.rootView;
  }

  private LayoutInflater mInflater;

  // Constructors
  public ChooseProductListAdapter(Context context,
      List<ProductLedgerOriginal.ProductLedgerContent> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }

  public ChooseProductListAdapter(Context context,
      ProductLedgerOriginal.ProductLedgerContent[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }

  @Override public boolean isEmpty() {
    return false;
  }
}

